package com.bdqn.spark.chapter05.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark09_RDD_Operator_Action {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("action-countByKey")
    val sc = new SparkContext(sparkConf)

    // 行动算子
//    val rdd: RDD[(String, Int)] = sc.makeRDD(List(
//      ("a", 1), ("a", 2), ("a", 3)
//    ))
//    val stringToLong: collection.Map[String, Long] = rdd.countByKey()
//    println(stringToLong)

    val rdd = sc.makeRDD(List(1,1,1,4),2)
    val intToLong: collection.Map[Int, Long] = rdd.countByValue()
    println(intToLong)

    sc.stop()
  }
}
